package com.compomics.proteocloud.model;

import com.compomics.proteocloud.db.accessor.Pepnovohit;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

/**
 * The instance of the DenovoSearchResult class holds the results for the de-novo search result.
 * @author Thilo Muth
 *
 */
public class DenovoSearchResult {

    /**
     * The title to denovo hit set mappping.
     */
    private Map<String, DenovoHitSet> titleToSetMap = new HashMap<String, DenovoHitSet>();

    /**
     * The project title.
     */
    private String projectTitle;

    /**
     * The de novo search result.
     * @param projectTitle The project title.
     */
    public DenovoSearchResult(String projectTitle) {
        this.projectTitle = projectTitle;
    }

    /**
     * Add a tag hit to the de novo search result
     * @param title Title of the spectrum
     * @param spectrumId The spectrum id
     * @param hit The Pepnovohit
     */
    public void addHitSet(String title, int spectrumId, Pepnovohit hit) throws IOException, SQLException {
        if(titleToSetMap.containsKey(title)) {
            titleToSetMap.get(title).addHit(hit);
        } else {
            DenovoHitSet hitSet = new DenovoHitSet(title, spectrumId, hit);
            titleToSetMap.put(title, hitSet);
        }
    }

    /**
     * Returns <code>true</code> if this result object contains no de novo hits.
     *
     * @return <code>true</code> if this result object contains no de novo hits.
     */
    public boolean isEmpty() {
        return titleToSetMap.isEmpty();
    }

    /**
     * Returns the project title.
     * @return The project title.
     */
    public String getProjectTitle() {
        return projectTitle;
    }

    /**
     * Returns the title to spectrum id mapping.
     * @return Title to spectrum id mapping.
     */
    public Map<String, DenovoHitSet> getTitleToHitSet() {
        return titleToSetMap;
    }
}